import random
import time

class Point():
  def __init__(self, x, y):
    self.x = x
    self.y = y

class Test():
  def __init__(self, string, nb):
    self.string = string
    self.points = []
    # 初始化点集合
    for i in range(nb):
      self.points.append(Point(random.random(), random.random()))
    self.distances = []

  # 增量字符串
  def increment_string(self, n):
    tmp = ""
    # 每个字符做一次偏移
    for c in self.string:
      tmp += chr(ord(c) + n)
    self.string = tmp

  # 这个函数计算列表中每个点之间的距离
  def distance_between_points(self):
    for i, a in enumerate(self.points):
      for b in self.points:
        # 距离公式
        self.distances.append(((b.x - a.x) ** 2 + (b.y - b.x) ** 2) ** 0.5)

if __name__ == '__main__':
  start_time = time.time()
  test = Test("A nice sentence to test.", 10000)
  test.increment_string(-5) # 偏移字符串中的每个字符
  test.distance_between_points() # 计算集合中点与点之间的距离
  print('pure python run time:%s'%str(time.time()-start_time))
